package cn.dujc.superkid.fragment.MyCourserFragment;

import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import cn.dujc.core.ui.BaseFragment;
import cn.dujc.core.util.ToastUtil;
import cn.dujc.superkid.R;
import cn.dujc.superkid.adapter.MyCourseAdapterRight;
import cn.dujc.superkid.api.HttpHelper;
import cn.dujc.superkid.api.QMap;
import cn.dujc.superkid.api.Result;
import cn.dujc.superkid.api.ResultCallBack;
import cn.dujc.superkid.bean.MyClassResult;
import cn.dujc.superkid.bean.RegisterResult;
import cn.dujc.superkid.utils.Preferences;

public class CupGameFragment extends BaseFragment {
        private RecyclerView recyclerView;

      private List<MyClassResult.MyClass> list = new ArrayList<>();
        private MyCourseAdapterRight myCourseAdapterRight;
        private RegisterResult loginResult;
        @Override
        public int getViewId() {
            return R.layout.fragment_cup_game;
        }

        @Override
        public void initBasic(Bundle savedInstanceState) {
            init();
            initLogic();
        }

        private void initLogic() {
            loaddata();
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getActivity());
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(linearLayoutManager);
            //分割线
            recyclerView.addItemDecoration(new DividerItemDecoration(this.getActivity(), linearLayoutManager.getOrientation()));
            myCourseAdapterRight = new MyCourseAdapterRight(list,getContext());
            recyclerView.setAdapter(myCourseAdapterRight);
        }

        private void init() {
            recyclerView = (RecyclerView) findViewById(R.id.mycourse_recyclerview);
        }
        private void loaddata(){

            loginResult = Preferences.getInstance().getLoginResult(mActivity);
            HttpHelper.getUserCenter().memberMyClass(QMap.build()
                    .put("user_id", Integer.parseInt(loginResult.getUid()))
                    .put("page", 1)
                    .put("num",1 )
                    .put("type_id",2 )
                    .put("channel",  Preferences.getInstance().getChannel(mActivity).getChannel_id())
                    .put("logincode",loginResult.getLogincode() ).create()).enqueue(new ResultCallBack<Result<MyClassResult>>(mActivity) {
                @Override
                public void onSuccessCallback(int code, Result<MyClassResult> body) {
                    if (body!=null){
                        ToastUtil.showToast(mActivity, body.getMsg());

                    }
                }
            });
        }
    }
